﻿#pragma once

#include "../../Server/Settings.h"
#include "../../Server/MirEnvir/Envir.h"
#include "../../Server/MirDatabase/NPCInfo.h"
#include <string>
#include <vector>
#include <any>
#include "../../tangible_filesystem.h"

using namespace Server::MirDatabase;
using namespace Server::MirEnvir;

namespace Server
{
    class NPCInfoForm : public System::Windows::Forms::Form
    {
    public:
        std::string NPCListPath = Path::Combine(Settings::ExportPath, "NPCList.txt");

        virtual ~NPCInfoForm()
        {
            delete components;
            delete tabControl1;
            delete tabPage1;
            delete NPCIndexTextBox;
            delete label1;
            delete RemoveButton;
            delete AddButton;
            delete PasteMButton;
            delete CopyMButton;
            delete ExportButton;
            delete ImportButton;
            delete ExportSelectedButton;
            delete label11;
            delete OpenNButton;
            delete NFileNameTextBox;
            delete label29;
            delete NRateTextBox;
            delete ClearHButton;
            delete NNameTextBox;
            delete label13;
            delete label24;
            delete NImageTextBox;
            delete NXTextBox;
            delete label28;
            delete label30;
            delete NYTextBox;
            delete NPCInfoListBox;
            delete label2;
            delete MapComboBox;
            delete label6;
            delete label5;
            delete label4;
            delete label3;
            delete MinLev_textbox;
            delete label10;
            delete Day_combo;
            delete Class_combo;
            delete EndMin_num;
            delete EndHour_combo;
            delete label8;
            delete label9;
            delete StartMin_num;
            delete StartHour_combo;
            delete TimeVisible_checkbox;
            delete label7;
            delete MaxLev_textbox;
            delete Flag_textbox;
            delete label12;
            delete tabPage2;
            delete label14;
            delete ConquestHidden_combo;
        }

        Server::MirEnvir::Envir *getEnvir() const;

    private:
        std::vector<NPCInfo*> _selectedNPCInfos;

    public:
        NPCInfoForm();

    private:
        void AddButton_Click(std::any sender, EventArgs *e);
        void RemoveButton_Click(std::any sender, EventArgs *e);

        void UpdateInterface();

        void RefreshNPCList();

        void NPCInfoListBox_SelectedIndexChanged(std::any sender, EventArgs *e);

        void NFileNameTextBox_TextChanged(std::any sender, EventArgs *e);
        void NNameTextBox_TextChanged(std::any sender, EventArgs *e);
        void NXTextBox_TextChanged(std::any sender, EventArgs *e);
        void NYTextBox_TextChanged(std::any sender, EventArgs *e);
        void NImageTextBox_TextChanged(std::any sender, EventArgs *e);
        void NRateTextBox_TextChanged(std::any sender, EventArgs *e);

        void MapComboBox_SelectedIndexChanged(std::any sender, EventArgs *e);

        void NPCInfoForm_FormClosed(std::any sender, FormClosedEventArgs *e);




        void PasteMButton_Click(std::any sender, EventArgs *e);

        void ExportAllButton_Click(std::any sender, EventArgs *e);

        void ExportSelected_Click(std::any sender, EventArgs *e);

    public:
        void ExportNPCs(std::vector<NPCInfo*> &NPCs);

    private:
        void ImportButton_Click(std::any sender, EventArgs *e);

        void OpenNButton_Click(std::any sender, EventArgs *e);

        void MinLev_textbox_TextChanged(std::any sender, EventArgs *e);

        void HourShow_textbox_TextChanged(std::any sender, EventArgs *e);

        void MinutesShow_textbox_TextChanged(std::any sender, EventArgs *e);

        void Class_textbox_TextChanged(std::any sender, EventArgs *e);

        void CopyMButton_Click(std::any sender, EventArgs *e);

        void MaxLev_textbox_TextChanged(std::any sender, EventArgs *e);

        void Class_combo_SelectedIndexChanged(std::any sender, EventArgs *e);

        void Day_combo_SelectedIndexChanged(std::any sender, EventArgs *e);

        void TimeVisible_checkbox_CheckedChanged(std::any sender, EventArgs *e);

        void StartHour_combo_SelectedIndexChanged(std::any sender, EventArgs *e);

        void EndHour_combo_SelectedIndexChanged(std::any sender, EventArgs *e);

        void StartMin_num_ValueChanged(std::any sender, EventArgs *e);

        void EndMin_num_ValueChanged(std::any sender, EventArgs *e);

        void Flag_textbox_TextChanged(std::any sender, EventArgs *e);

        void dateTimePicker1_ValueChanged(std::any sender, EventArgs *e);

        void NPCInfoForm_Load(std::any sender, EventArgs *e);

        void ConquestHidden_combo_SelectedIndexChanged(std::any sender, EventArgs *e);


        /// <summary>
        /// Required designer variable.
        /// </summary>
        System::ComponentModel::IContainer *components = nullptr;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected:
        void Dispose(bool disposing) override;

        #pragma region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
    private:
        void InitializeComponent();

        #pragma endregion

        System::Windows::Forms::TabControl *tabControl1;
        System::Windows::Forms::TabPage *tabPage1;
        System::Windows::Forms::TextBox *NPCIndexTextBox;
        System::Windows::Forms::Label *label1;
        System::Windows::Forms::Button *RemoveButton;
        System::Windows::Forms::Button *AddButton;
        System::Windows::Forms::Button *PasteMButton;
        System::Windows::Forms::Button *CopyMButton;
        System::Windows::Forms::Button *ExportButton;
        System::Windows::Forms::Button *ImportButton;
        System::Windows::Forms::Button *ExportSelectedButton;
        System::Windows::Forms::Label *label11;
        System::Windows::Forms::Button *OpenNButton;
        System::Windows::Forms::TextBox *NFileNameTextBox;
        System::Windows::Forms::Label *label29;
        System::Windows::Forms::TextBox *NRateTextBox;
        System::Windows::Forms::Button *ClearHButton;
        System::Windows::Forms::TextBox *NNameTextBox;
        System::Windows::Forms::Label *label13;
        System::Windows::Forms::Label *label24;
        System::Windows::Forms::TextBox *NImageTextBox;
        System::Windows::Forms::TextBox *NXTextBox;
        System::Windows::Forms::Label *label28;
        System::Windows::Forms::Label *label30;
        System::Windows::Forms::TextBox *NYTextBox;
        System::Windows::Forms::ListBox *NPCInfoListBox;
        System::Windows::Forms::Label *label2;
        System::Windows::Forms::ComboBox *MapComboBox;
        System::Windows::Forms::Label *label6;
        System::Windows::Forms::Label *label5;
        System::Windows::Forms::Label *label4;
        System::Windows::Forms::Label *label3;
        System::Windows::Forms::TextBox *MinLev_textbox;
        System::Windows::Forms::Label *label10;
        System::Windows::Forms::ComboBox *Day_combo;
        System::Windows::Forms::ComboBox *Class_combo;
        System::Windows::Forms::NumericUpDown *EndMin_num;
        System::Windows::Forms::ComboBox *EndHour_combo;
        System::Windows::Forms::Label *label8;
        System::Windows::Forms::Label *label9;
        System::Windows::Forms::NumericUpDown *StartMin_num;
        System::Windows::Forms::ComboBox *StartHour_combo;
        System::Windows::Forms::CheckBox *TimeVisible_checkbox;
        System::Windows::Forms::Label *label7;
        System::Windows::Forms::TextBox *MaxLev_textbox;
        System::Windows::Forms::TextBox *Flag_textbox;
        System::Windows::Forms::Label *label12;
        System::Windows::Forms::TabPage *tabPage2;
        System::Windows::Forms::Label *label14;
        System::Windows::Forms::ComboBox *ConquestHidden_combo;
    };
}
